<template>
	<view class="page">
		<u--form
			class="basic-style"
			labelPosition="top"
			:model="basicForm"
			ref="form1"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-title basic-border">基础信息</view>
			<u-form-item
				label="单据编号"
				prop="documentNo"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					disabled
					placeholder="请输入单据编号"
					v-model="basicForm.documentNo"
					border="surround"
				></u--input>
			</u-form-item>
			<u-form-item
				label="申请人"
				prop="handlerId_dictText"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="basicForm.handlerId_dictText"
					disabled
					placeholder="请选择申请人"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="申请时间"
				prop="createTime"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="basicForm.createTime"
					disabled
					placeholder="请选择时间"
					border="surround"
					suffixIcon="calendar-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="申请部门"
				prop="applyDept_dictText"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					v-model="basicForm.applyDept_dictText"
					disabled
					placeholder="请选择申请部门"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="申请车辆"
				prop="carId_dictText"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					disabled
					placeholder="请选择申请车辆"
					v-model="basicForm.carId_dictText"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="管理员"
				prop="carAdmin_dictText"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="basicForm.carAdmin_dictText"
					placeholder="请选择人员"
					border="surround"
					disabled
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="费用所属团队"
				prop="businessUnit_dictText"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					v-model="basicForm.businessUnit_dictText"
					disabled
					placeholder="请选择费用所属团队"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="关联项目"
				prop="projectId_dictText"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="basicForm.projectId_dictText"
					disabled
					placeholder="请选择关联项目"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="是否需要驾驶员"
				prop="isDriver"
				:borderBottom="false"
				ref="item1"
				required
			>
				<!-- <h-dict-radio v-model="basicForm.isDriver" disabled dictName="YES_OR_NO"></h-dict-radio> -->
				<h-dict-select
					disabled
					style="width: 100%" 
					v-model="basicForm.isDriver" 
					placeholder="请选择是否需要驾驶员" 
					dictName="YES_OR_NO" 
					suffixIcon="arrow-down-fill" 
					:suffixIconStyle="{color: '#B2B2B2'}"
				></h-dict-select>
			</u-form-item>
			<u-form-item
				label="预计归还日期"
				prop="usingEndTime"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					v-model="basicForm.usingEndTime"
					disabled
					placeholder="请选择预计归还日期"
					border="surround"
					suffixIcon="calendar-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="用车类型"
				prop="usingType_dictText"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					v-model="basicForm.usingType_dictText"
					disabled
					placeholder="请选择用车类型"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="预定日期"
				prop="reserveStartTime"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--input
					v-model="reserveStartTime"
					disabled
					placeholder="请选择预计归还日期"
					border="surround"
					suffixIcon="calendar-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			至
			<u-form-item
				label=""
				prop="reserveEndTime"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="reserveEndTime"
					disabled
					placeholder="请选择预计归还日期"
					border="surround"
					suffixIcon="calendar-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				v-if="basicForm.isDriver == '1'"
				label="驾驶员"
				prop="driver"
				:borderBottom="false"
				ref="item1"
			>
				<h-select-person-input
					v-model="basicForm.driver"
					style="width: 100%" 
					placeholder="请选择人员"
					border="surround"
					suffixIcon="arrow-down-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
					objectField = 'basicForm.driver'
				></h-select-person-input>
			</u-form-item>
			<u-form-item
				label="是否已还车"
				prop="isReturnCar"
				:borderBottom="false"
				ref="item1"
			>
				<h-dict-radio v-model="basicForm.isReturnCar" disabled dictName="YES_OR_NO"></h-dict-radio>
			</u-form-item>
			<u-form-item
				label="还车日期"
				prop="returnCarTime"
				:borderBottom="false"
				ref="item1"
			>
				<u--input
					v-model="basicForm.returnCarTime"
					disabled
					placeholder="请选择还车日期"
					border="surround"
					suffixIcon="calendar-fill"
					:suffixIconStyle="{color: '#B2B2B2'}"
				></u--input>
			</u-form-item>
			<u-form-item
				label="事由"
				prop="subjectMatter"
				:borderBottom="false"
				ref="item1"
				required
			>
				<u--textarea disabled v-model="basicForm.subjectMatter" confirmType="done" placeholder="请输入事由" ></u--textarea>
			</u-form-item>
			<u-form-item
				label="备注"
				prop="remark"
				:borderBottom="false"
				ref="item1"
			>
				<u--textarea disabled v-model="basicForm.remark" confirmType="done" placeholder="请输入备注" ></u--textarea>
			</u-form-item>
		</u--form>
		
		<!-- 附件 -->
		<view class="basic-style">
			<view class="basic-title basic-border">附件信息</view>
			<!-- <file-list :fileList="basicForm.attachment" style="padding-top:16rpx"></file-list> -->
			<view class="" style="width: 100%;">
				<!-- <h-upload-file v-model="basicForm.fileInfo" :isIcon="false"></h-upload-file> -->
				<file-list v-if="basicForm.fileInfo" v-model="basicForm.fileInfo"></file-list>
			</view>
		</view>
		<view class="space-x-1 px-1 btn_position">
			<backButton  @onSubmit="onSubmit" :nodeObj="nodeObj" :model="model" :resultObj="resultObj"></backButton>
		</view>
		<view style="height: 100rpx;"></view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import fileList from './components/fileList.vue'
import backButton from '@/components/backButton.vue'
import {
	queryByIdCarUsing, // 根据id查询车辆使用详情
	getProcessTaskTransInfo, // 流程流转
	editCarUsing // 编辑车辆使用详情
} from '@/api/index.js'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
export default {
	components: {
		fileList,
		backButton
	},
	data() {
		return {
			isSubmit: false, // 是否点击提交
			basicForm: {},
			nodeObj: {},
			tabvalue:'',
			id: '', // 详情id值
			model: {},
			resultObj: {}, // 流程图流转信息
		};
	},
	onLoad(options) {
		this.model = JSON.parse(decodeURIComponent(options.item))
		var that = this
		// #ifdef APP-NVUE
			var eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
		// #endif
		// #ifndef APP-NVUE
			var eventChannel = this.getOpenerEventChannel();
		// #endif
		// 监听sendMessage事件，获取上一页面通过eventChannel传送到当前页面的数据
		eventChannel.on('sendMessage', function(data) {
			that.tabvalue = data.tabvalue
			that.nodeObj = JSON.parse(decodeURIComponent(data.nodeObj))
			that.id = that.nodeObj.dataId
			that.loadData(that.nodeObj.dataId)
			that.getProcessTaskTrans(that.model.id)
		})
	},
	computed:{
		// 修改预定日期开始日期
		reserveStartTime: {
			get () {
				if (this.basicForm.reserveStartTime) {
					var reserveStartTime = this.basicForm.reserveStartTime.split(' ')
					return reserveStartTime[0]
				} else {
					return ''
				}
			},
			set (val) {
				return val
			}
		},
		// 修改预定日期结束日期
		reserveEndTime: {
			get () {
				if (this.basicForm.reserveEndTime) {
					var reserveEndTime = this.basicForm.reserveEndTime.split(' ')
					return reserveEndTime[0]
				} else {
					return ''
				}
			},
			set (val) {
				return val
			}
		}
	},
	methods: {
		loadData(id){
			queryByIdCarUsing({ id }).then(res => {
				if(res.success){
					this.basicForm = res.result
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		// 查询流程流转信息 -- 获取下一节点信息
		getProcessTaskTrans(taskId){
			getProcessTaskTransInfo({ taskId }).then(res => {
				if(res.success){
					this.resultObj = res.result
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			}).catch(err => {
				console.log(err);
			})
		},
		
		// 点击提交
		onSubmit () {
			var _this = this
			var params = this.basicForm
			editCarUsing(params).then(res => {
				if (res.success) {
					// this.getManagerClassList = res.result || []
					this.isSubmit = true // 是否提交
					this.$refs.uToast.show({
						message: '提交成功',
						type: 'success',
						complete () {
							_this.onAudit()
						}
					})
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onAudit() {
			if (!this.isSubmit) {
				uni.showToast({
					title: '请完善表单后审核',
					icon: 'none'
				})
				return false
			}
			var that = this
			uni.navigateTo({
				url: '/pages/synergy/erpCarUsingList'+`?item=${encodeURIComponent(JSON.stringify(this.model).replace(/%/g, '%25'))}`,
				events: {
					// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
					// acceptDataFromOpenedPage: function(data) {
					// }
				},
				success: function(data) {
					// 通过eventChannel向被打开页面传送数据
					var params = {
						nodeObj: encodeURIComponent(JSON.stringify(that.nodeObj).replace(/%/g, '%25')),
						tabvalue: that.tabvalue
					}
					data.eventChannel.emit('sendMessage', params)
				},
				fail: function(err) {
					this.$refs.uToast.show({
						message: '请联系管理员配置',
						type: 'error'
					})
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
// 评测信息
.info-title{
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #171717;
	line-height: 40rpx;
	padding-bottom: 16rpx;
}

// 评测结果
.result-style{
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #B2B2B2;
}

.inforamtion{
	margin-top: 10rpx;
	padding: 10rpx;
	border-radius: 15rpx;
	box-shadow: 0px 4px 20px 0px rgba(0,0,0,0.1);
}
</style>